package com.lineage.data.item_etcitem.dragon;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1BuffUtil;
import com.lineage.server.model.skill.L1SkillMode;
import com.lineage.server.model.skill.skillmode.SkillMode;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.sql.Timestamp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class EyeX_Figure extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(EyeX_Figure.class);
  
  public static ItemExecutor get() {
    return new EyeX_Figure();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    try {
      if (item == null)
        return; 
      if (pc == null)
        return; 
      int time = L1BuffUtil.cancelDragon(pc);
      if (time != -1) {
        pc.sendPackets(
            (ServerBasePacket)new S_ServerMessage(1139, String.valueOf(String.valueOf(item.getLogName())) + " " + String.valueOf(time / 60)));
        return;
      } 
      pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 7676));
      Timestamp ts = new Timestamp(System.currentTimeMillis());
      item.setLastUsed(ts);
      pc.getInventory().updateItem(item, 32);
      pc.getInventory().saveItem(item, 32);
      SkillMode mode = L1SkillMode.get().getSkill(6689);
      if (mode != null)
        mode.start(pc, null, null, 600); 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
